//
//  CalculatorButtonPad.swift
//  ToDo
//
//  Created by yanhangpu on 2021/7/7.
//

import SwiftUI

struct CalculatorButtonPad: View {
    
    @Binding var brain: CalculatorBrain
    
    let pad: [[CalculatorButtonItem]] = [
        [.command(.clear), .command(.flip), .command(.percent), .operation(.divide)],
        [.digit(7), .digit(8), .digit(9), .operation(.multiply)],
        [.digit(4), .digit(5), .digit(6), .operation(.plus)],
        [.digit(1), .digit(2), .digit(3), .operation(.minus)],
        [.digit(0), .dot, .operation(.equal)]
    ]
    var body: some View {
        VStack(alignment: .center, spacing: 8, content: {
            ForEach(pad, id: \.self) { row in
                CalculatorButtonRow(row: row, brain: $brain)
            }
        })
    }
}

struct CalculatorButtonPad_Previews: PreviewProvider {
    static var previews: some View {
        CalculatorButtonPad(brain: .constant(.left("0")))
    }
}
